<?php

class Groups_model extends CI_Model
{
  private $module = 'users';
  private $table = 'groups';

  function getsearchContent($limit,$page){
    $this->db->select('*');
    $this->db->limit($limit,$page);
    $this->db->order_by($this->input->post('func_order_by'),$this->input->post('order_by'));
    if($this->input->post('content')!='' && $this->input->post('content')!='type here...'){
      $this->db->where('(`name` LIKE "%'.$this->input->post('content').'%")');
    }
    if($this->input->post('dateFrom')!='' && $this->input->post('dateTo')==''){
      $this->db->where('created >= "'.date('Y-m-d 00:00:00',strtotime($this->input->post('dateFrom'))).'"');
    }
    if($this->input->post('dateFrom')=='' && $this->input->post('dateTo')!=''){
      $this->db->where('created <= "'.date('Y-m-d 23:59:59',strtotime($this->input->post('dateTo'))).'"');
    }
    if($this->input->post('dateFrom')!='' && $this->input->post('dateTo')!=''){
      $this->db->where('created >= "'.date('Y-m-d 00:00:00',strtotime($this->input->post('dateFrom'))).'"');
      $this->db->where('created <= "'.date('Y-m-d 23:59:59',strtotime($this->input->post('dateTo'))).'"');
    }
    $query = $this->db->get(PREFIX.$this->table);

    if($query->result()){
      return $query->result();
    }else{
      return false;
    }
  }
  function getTotalsearchContent(){
    $this->db->select('*');
    if($this->input->post('content')!='' && $this->input->post('content')!='type here...'){
      $this->db->where('(`name` LIKE "%'.$this->input->post('content').'%")');
    }
    if($this->input->post('dateFrom')!='' && $this->input->post('dateTo')==''){
      $this->db->where('created >= "'.date('Y-m-d 00:00:00',strtotime($this->input->post('dateFrom'))).'"');
    }
    if($this->input->post('dateFrom')=='' && $this->input->post('dateTo')!=''){
      $this->db->where('created <= "'.date('Y-m-d 23:59:59',strtotime($this->input->post('dateTo'))).'"');
    }
    if($this->input->post('dateFrom')!='' && $this->input->post('dateTo')!=''){
      $this->db->where('created >= "'.date('Y-m-d 00:00:00',strtotime($this->input->post('dateFrom'))).'"');
      $this->db->where('created <= "'.date('Y-m-d 23:59:59',strtotime($this->input->post('dateTo'))).'"');
    }
    $query = $this->db->count_all_results(PREFIX.$this->table);

    if($query > 0){
      return $query;
    }else{
      return false;
    }
  }
}